package com.module.aichat.ui.widget.inputview


import android.view.View
import android.widget.LinearLayout
import com.module.aichat.data.bean.InputModel

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：3/11/2023
 *
 * 描述：
 *
 * 修订历史：
 *
 */
class ChatEditor private constructor(
    private val inputView: ChatInputView
) {


    /**
     * 更换模式
     */
    fun switchModel(model: InputModel) {
        inputView.switchModel(model)
    }

    /**
     * 设置输入框是否可用
     */
    fun setEnabled(isEnabled: Boolean) {
        inputView.isEnabled = isEnabled
    }

    class Build constructor(
        private val inputView: ChatInputView,
        contentView: View
    ) {
        init {
            if (contentView.parent != inputView.parent ||
                inputView.parent !is LinearLayout ||
                (inputView.parent as LinearLayout).orientation != LinearLayout.VERTICAL
            ) {
                throw RuntimeException("inputView和contentView必须同在一个LinearLayout中 并且LinearLayout方向是VERTICAL")
            }
            inputView.setContentView(contentView)
        }

        private var chatInputListener: ChatInputListener? = null

        /**
         * 绑定监听器
         */
        fun bindListener(chatInputListener: ChatInputListener): Build {
            this.chatInputListener = chatInputListener
            return this
        }

        fun builder(): ChatEditor {
            val chatEditor = ChatEditor(inputView)
            //设置事件回调
            inputView.chatInputListener = chatInputListener
            return chatEditor
        }
    }
}